<?php

/*
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Library General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

namespace EasyActionPHP\Log;

 /**
  * @author Flavio de Vasconcellos Correa
  * @since 2008/07/08
  * @package EasyActionPHP
  * @subpackage Log
  * @version $id$
  */
class ActionLogger {

    private $level;
    private $appender;

    public function __construct() {
        $this->level = LoggerLevel::ALL;
        $this->appender = new FileAppender('WEB-INF/log/' . date('Ymd') . '.log');
    }

    public function setLevel($level) {
        if ($level >= LoggerLevel::ALL or $level <= LoggerLevel::WARN) {
            $this->level = $level;
        } else {
            throw (new \Exception('ERROR:' . __METHOD__ . ' in line ' . __LINE__ . '. LoggerLevel passed out of bounds'));
        }
    }

    public function getLevel() {
        return $this->level;
    }

    public function trace($message) {
        if ($this->level >= LoggerLevel::TRACE) {
            $this->appender->append("TRACE [" . date('d/m/Y h:i:s') . "] - " . $message);
        }
    }

    public function debug($message) {
        if ($this->level >= LoggerLevel::DEBUG) {
            $this->appender->append("DEBUG [" . date('d/m/Y h:i:s') . "] - " . $message);
        }
    }

    public function info($message) {
        if ($this->level >= LoggerLevel::INFO) {
            $this->appender->append("INFO [" . date('d/m/Y h:i:s') . "] - " . $message);
        }
    }

    public function warn($message) {
        if ($this->level >= LoggerLevel::WARN) {
            $this->appender->append("WARN [" . date('d/m/Y h:i:s') . "] - " . $message);
        }
    }

    public function error($message) {
        if ($this->level >= LoggerLevel::ERROR) {
            $this->appender->append("ERROR [" . date('d/m/Y h:i:s') . "] - " . $message);
        }
    }

    public function fatal($message) {
        if ($this->level >= LoggerLevel::FATAL) {
            $this->appender->append("FATAL [" . date('d/m/Y h:i:s') . "] - " . $message);
        }
    }

}

?>
